package com.openbravo.pos.panels.link;

import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import cn.ekuma.epos.datalogic.I_DataLogicSales;

import com.openbravo.bean.Product;
import com.openbravo.bean.erp.viewbean.LotNoStockCurrentInfo;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.query.QBFCompareEnum;
import com.openbravo.pos.panels.link.model.ProductLotNoStoreVTableModel;

public class JProductLotNoStorePanel extends AbstractProductLinkTablePanel<LotNoStockCurrentInfo>{


	private ButtonGroup buttonGroup1;
	private JRadioButton jCode7;
	private JRadioButton jCode8;
	private JRadioButton jCode9;
	private JRadioButton jCode10;


	/** Creates new form JProductStorePanel */
    public JProductLotNoStorePanel(I_DataLogicSales dlSales) {
       super(dlSales,new ProductLotNoStoreVTableModel());
    }
 
    
	@Override
	public void baseBeanChanged(Product o) {
		 try {
	            tableModel.resert(dlSales.listByFilter(LotNoStockCurrentInfo.class,createValue()));
	        } catch (BasicException ex) {
	        	new MessageInf(ex).show(this);
	        	tableModel.resert(null);
	      }
		
	}

	@Override
	public JPanel getToolBar() {
		JPanel toolbar=new JPanel();
		buttonGroup1 = new javax.swing.ButtonGroup();
        jCode7 = new javax.swing.JRadioButton();
        jCode8 = new javax.swing.JRadioButton();
        jCode9 = new javax.swing.JRadioButton();
        jCode10 = new javax.swing.JRadioButton();

        toolbar.setLayout(new javax.swing.BoxLayout(toolbar, javax.swing.BoxLayout.LINE_AXIS));

        buttonGroup1.add(jCode7);
        jCode7.setText("<0"); // NOI18N
        jCode7.setFocusPainted(false);
        jCode7.setFocusable(false);
        toolbar.add(jCode7);

        buttonGroup1.add(jCode8);
        jCode8.setText("=0"); // NOI18N
        jCode8.setFocusPainted(false);
        jCode8.setFocusable(false);
        toolbar.add(jCode8);

        buttonGroup1.add(jCode9);
        jCode9.setSelected(true);
        jCode9.setText(">0"); // NOI18N
        jCode9.setFocusPainted(false);
        jCode9.setFocusable(false);
        toolbar.add(jCode9);

        buttonGroup1.add(jCode10);
        jCode10.setText("All"); // NOI18N
        jCode10.setFocusPainted(false);
        jCode10.setFocusable(false);
        toolbar.add(jCode10);
		return toolbar;
	}

	@Override
	public Object createValue() throws BasicException {
		QBFCompareEnum unitCompare=QBFCompareEnum.COMP_NONE;
        if(jCode7.isSelected())
        	unitCompare=QBFCompareEnum.COMP_LESS;
        else if(jCode8.isSelected())
        	unitCompare=QBFCompareEnum.COMP_EQUALS;
        else if(jCode9.isSelected())
        	unitCompare=QBFCompareEnum.COMP_GREATER;
        return new Object[] {
        		QBFCompareEnum.COMP_EQUALS, baseBeanID,
        		unitCompare, new Double(0)
       };
	}
}
